package com.chengh.springboot.async.manager.factory;

import lombok.extern.slf4j.Slf4j;

import java.util.TimerTask;

/**
 * 异步工厂（产生任务用）
 */
@Slf4j
public class AsyncFactory {

    /**
     * 测试任务1
     */
    public static TimerTask test1(final String str) {
        return new TimerTask() {
            @Override
            public void run() {
                log.info(Thread.currentThread().getName() + "start");
                log.info(str);
                try {
                    Thread.sleep(1000);
                    log.info(Thread.currentThread().getName() + "end");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
    }

    /**
     * 测试任务2
     */
    public static TimerTask test2(final String str) {
        return new TimerTask() {
            @Override
            public void run() {
                log.info(Thread.currentThread().getName() + "start");
                log.info(str);
                try {
                    Thread.sleep(1000);
                    log.info(Thread.currentThread().getName() + "end");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
    }
}
